﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using OF.Common;
using System.Data;
namespace OF.Web.user
{
    public partial class userinfo : BuyerAdminPage
    {

        DAL.Buyer dal_buyer = new DAL.Buyer();
        Model.Buyer model;
        int id = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                id = WebUtils.GetBuyerId();

                #region 绑定信息
                model = dal_buyer.GetModel(id);
                if (model != null)
                {
                    hfid.Value = id.ToString();
                    txtloginname.Text = model.loginname;
                    if (!string.IsNullOrWhiteSpace(model.name))
                        txtname.Text = model.name;
                    if (model.regsource != null)
                        ddlsource.SelectedValue = model.regsource.ToString();
                    jifen.Text =model.jifen==null?"0": model.jifen.ToString();
                }

                #endregion
            }
        }

        #region 提交

        protected void btnSave_Click(object sender, EventArgs e)
        {

            model = dal_buyer.GetModel(Convert.ToInt32(hfid.Value));

            model.name = txtname.Text;
            string str = ddlsource.SelectedValue;
            model.regsource = string.IsNullOrWhiteSpace(str) ? 0 : Convert.ToInt32(str);
           
            //更新或添加商家信息
            bool result = dal_buyer.Update(model);
            if (result)
            {
                MessageBox.Show(this, "操作成功");
            }
            else
            {
                MessageBox.Show(this, "操作失败");
            }
        }
        #endregion

    }
}